#include <iostream>
#include <vector>
#include <algorithm>

int main() {

    auto greet = []() {
        std::cout << "Hello, Lambda!" << std::endl;
    };
    greet();

    auto add = [](int a, int b) {
        return a + b;
    };
    std::cout << "5 + 3 = " << add(5, 3) << std::endl;

    int x = 10;
    auto increment = [x](int y) { 
        return x + y;
    };
    std::cout << "10 + 7 = " << increment(7) << std::endl;

    int counter = 0;
    auto count = [&counter]() { 
        counter++;
    };
    count();
    count();
    std::cout << "Counter: " << counter << std::endl;

    std::vector<int> numbers = {1, 2, 3, 4, 5};
    std::for_each(numbers.begin(), numbers.end(), [](int n) {
        std::cout << n << " ";
    });
    std::cout << std::endl;

    int a = 5;
    auto modify = [a]() mutable { 
        std::cout << "Inside lambda (before): " << a << std::endl;
        a = 10;
        std::cout << "Inside lambda (after): " << a << std::endl;
    };
    modify();
    std::cout << "Outside lambda: " << a << std::endl;

    int m = 1, n = 2;
    auto captureAll = [=]() { 
        std::cout << "m: " << m << ", n: " << n << std::endl;
    };
    captureAll();

    auto captureRefAll = [&]() { 
        m++;
        n++;
    };
    captureRefAll();
    std::cout << "After ref capture: m=" << m << ", n=" << n << std::endl;

    return 0;
}